package cn.edu.web;

import cn.edu.pojo.Brand;
import cn.edu.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Davey chan
 */
@WebServlet("/addServlet")
public class AddServlet extends HttpServlet {
    private BrandService brandService = new BrandService();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        处理中文乱码
        request.setCharacterEncoding("utf-8");
//        获取表单的数据
        String brandName = request.getParameter("brandName");
        String companyName = request.getParameter("companyName");
        String description = request.getParameter("description");
        String ordered= request.getParameter("ordered");
        String status = request.getParameter("status");
//        封装
        Brand brand=new Brand();
        brand.setStatus(Integer.parseInt(status));
        brand.setBrandName(brandName);
        brand.setCompanyName(companyName);
        brand.setDescription(description);
        brand.setOrdered(Integer.parseInt(ordered));
//        添加
        brandService.add(brand);
//        转发到查询所有的Serlvet
        request.getRequestDispatcher("/selectAllServlet").forward(request,response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }


}
